﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentStateRecordVMs
{
    public partial class EquipmentStateRecordListVM : BasePagedListVM<EquipmentStateRecord_View, EquipmentStateRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentStateRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentStateRecord_View>>{
                
                this.MakeGridHeader(x => x.EquipmentStateRecord_LineId).SetTitle(@Localizer["Page.产线编号"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_LineName).SetTitle(@Localizer["Page.产线名称"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_ProuductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_Equipment).SetTitle(@Localizer["Page.设备"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_EquipName).SetTitle(@Localizer["Page.设备名称"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_Status).SetTitle(@Localizer["Page.设备状态"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_StartTime).SetTitle(@Localizer["Page.开始时间"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_EndTime).SetTitle(@Localizer["Page.结束时间"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_Duration).SetTitle(@Localizer["Page.持续时长"].Value),
                this.MakeGridHeader(x => x.EquipmentStateRecord_ActiveOee).SetTitle(@Localizer["Page.OEE激活"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentStateRecord_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentStateRecord>()
                
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineName, x=>x.LineName)
                .CheckEqual(Searcher.ProuductId, x=>x.ProuductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckContain(Searcher.EquipName, x=>x.EquipName)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckBetween(Searcher.EndTime?.GetStartTime(), Searcher.EndTime?.GetEndTime(), x => x.EndTime, includeMax: false)
                .CheckEqual(Searcher.Duration, x=>x.Duration)
                .CheckEqual(Searcher.ActiveOee, x=>x.ActiveOee)
                .Select(x => new EquipmentStateRecord_View
                {
				    ID = x.ID,
                    
                    EquipmentStateRecord_LineId = x.LineId,
                    EquipmentStateRecord_LineName = x.LineName,
                    EquipmentStateRecord_ProuductId = x.ProuductId,
                    EquipmentStateRecord_ProductName = x.ProductName,
                    EquipmentStateRecord_Equipment = x.Equipment.TenantCode,
                    EquipmentStateRecord_EquipName = x.EquipName,
                    EquipmentStateRecord_Status = x.Status,
                    EquipmentStateRecord_StartTime = x.StartTime,
                    EquipmentStateRecord_EndTime = x.EndTime,
                    EquipmentStateRecord_Duration = x.Duration,
                    EquipmentStateRecord_ActiveOee = x.ActiveOee,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentStateRecord_View: EquipmentStateRecord
    {
        
        public long? EquipmentStateRecord_LineId { get; set; }
        public string EquipmentStateRecord_LineName { get; set; }
        public long? EquipmentStateRecord_ProuductId { get; set; }
        public string EquipmentStateRecord_ProductName { get; set; }
        public string EquipmentStateRecord_Equipment { get; set; }
        public string EquipmentStateRecord_EquipName { get; set; }
        public EquipStatusEnum? EquipmentStateRecord_Status { get; set; }
        public DateTime? EquipmentStateRecord_StartTime { get; set; }
        public DateTime? EquipmentStateRecord_EndTime { get; set; }
        public decimal? EquipmentStateRecord_Duration { get; set; }
        public bool? EquipmentStateRecord_ActiveOee { get; set; }

    }

}